package cn.ilovese.collect.serviceimpl.report.similaritystrategy;

import cn.ilovese.collect.po.report.Report;
import cn.ilovese.collect.service.report.similaritystrategy.TextSimilarityStrategy;
import cn.ilovese.collect.vo.report.ReportFormVO;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
@Service
public class Word2VecStrategy implements TextSimilarityStrategy {
    //TODO
    @Override
    public Double CalcSimilarity(ReportFormVO reportVO,Integer taskid) {
        return null;
    }

    @Override
    public Double CalSimilarityOneToOne(Report first, Report second) throws IOException {
        String firstInfo = first.getDescription() + first.getSteps() + first.getDeviceInfo();
        String secondInfo = second.getDescription() + second.getSteps() + second.getDeviceInfo();
        System.out.println(firstInfo + ";" + secondInfo);
//        //TODO pythonPath改成本地python路径
//        //TODO codePath改成本地py文件路径
        String pythonPath = "D:\\Software\\Python\\python.exe";
        String codePath = "D:\\NJU\\Junior(2)\\CSEIII\\Backend-new\\backend-collect\\src\\main\\resources\\python\\my_word2vec.py";
        try{
            Process python_process;
            String[] exe_process = new String[]{pythonPath,codePath,firstInfo,secondInfo};
            python_process = Runtime.getRuntime().exec(exe_process);
            System.out.println(python_process.waitFor());
            InputStreamReader ir = new InputStreamReader(python_process.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String result = input.readLine();
            Double res = Double.parseDouble(result);
            input.close();
            ir.close();
            python_process.destroy();
            return res;
        }catch (InterruptedException exception){
            exception.printStackTrace();
        }
        return 0.0;
    }
}
